indusfandomcom-20200214-history
Context, newType and main( )
Indus is a language for distributed computing. An Indus program that is implemented to run on a distributed network is the same as one implemented to run on a local machine. This is facilitated by new features in Indus like a program’s Context and mechanism to invoke agents and components over a network. As is probably evident by now, an Indus program executes in an Indus container. The Indus container provides services to agents and components hosted in them. An Indus container uses the Context of an agent or component to provide it with services such as service discovery, local and remote connections, transactions and policies. A program is therefore separate from the program's Context that constructs and populates it. Context A Context is created dynamically when an Agent or Component is instantiated. A Context of an Agent or Component contains meta-data on it. Meta-data contained in a Context is used for * Discovery of remote components and agents the component or agent communicates with * Establishing inter-operable, fault tolerant connections with remote components and agents * Routing messages across a network by the shortest, fault tolerant available to an agent or component * Specifying additional behavior at run time, i.e. setting contracts or policies * Facilitating transaction management When an agent or component is instantiated, it constructs its context and configures it according to information set by the programmer in the context constructor of the agent/component implementation. For example: Context { //Set the context attributes setServantType("USER"); setNetworkTypes("HTTP"); setPeerDetails("192.168.1.152",9001,"HTTP"); setPackage(".",".\MyPackage"); } The Indus compiler checks for * Presence of the Context constructor * Setting of the ServantType correctly that allows only specific agent and component implementation types in Indus * Setting PackageNames in Context newType Before we discuss implementation types of agents and components in Indus, it is important to understand the use of newType in an Indus agent and component implementation. newType( ) in Indus is different from new( ) in Java. Both facilitate class instantiation but in Indus, instantiations of classes that implement agents and components can also be done across a distributed network. This implies that newType( ) in Indus also involves service discovery across a network. In addition, newType( ) realize the concept of client side handles and server side instances in Indus. Instances in Indus are of several types and these are referred to as ‘Implementation types’ in Agent implementation types and Component implementation types. Instances of agents and components behave differently in Indus by their implementation type, for example, some instances may be persistent and others not. In Indus, newType( ) is being used as ClassName ClientHandle = newType ClassName(ServerInstanceID) Where, ServerInstanceID is optional and where ClientHandle corresponds to the ServerInstance created using newType( ). Use of main( ) main(String[ ] args) does not get the same treatment in Indus as in Java. Like in Java, an Indus application or a set of Indus classes must have a main( ) function to become accessible or invocable. However, main functions are not allowed to be implemented in Indus components as components are only supposed to be invoked from within Indus agent implementations. Even in the case of agents, main is used differently in the case of different agent implementation types. Next : Agent implementation types and Next : Component implementation types